<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/templates/mainLayout.xhtml">
    <f:metadata>
        <f:viewParam id="categoryId" name="categoryId" value="#{categoryBean.categoryId}" />
        <f:viewParam id="pageNum" name="pageNum" value="#{categoryBean.pageNum}" />
    </f:metadata>
    <ui:define name="title" rendered="#{categoryBean.currentCategory != null}">#{categoryBean.currentCategory.name}</ui:define>
    <ui:define name="meta">
        <meta name="keywords" content="#{categoryBean.currentCategory.description}" />
        <meta name="description" content="#{categoryBean.currentCategory.description}" />
    </ui:define>
    <ui:define name="menu">
        <nav class="vertical menu">
            <ul>
                <ui:repeat value="#{categoryBean.categoryList}" var="category">
                    <h:panelGroup rendered="#{category.devices.size() > 0 ? (category.devices.contains(session.getAttribute('DEVICE'))) : true}">
                        <li>
                            <a style="background: lightyellow; font-weight: bold; color: hotpink;" href="#{request.contextPath}/category/#{category.id}/#{category.url}">
                            #{category.name}
                            </a>
                        </li>
                    </h:panelGroup>
                </ui:repeat>
            </ul>
        </nav>
    </ui:define>
    <ui:define name="content">
        <div class="content">
            <ui:repeat value="#{categoryBean.itemList}" var="item">
                <h:panelGroup rendered="#{item.devices.size() > 0 ? (item.devices.contains(session.getAttribute('DEVICE'))) : true}">
                    <article class="underline">
                        <h:panelGroup rendered="#{item.thumbnailURL != null and item.thumbnailURL.length() > 0}">
                            <div class="post-preview">
                                <a href="#{request.contextPath}/item/#{item.id}/#{item.url}">
                                    <h:graphicImage value="#{item.thumbnailURL}" alt="#{item.name}"
                                                    rendered="#{item.thumbnailURL != null and item.thumbnailURL.length() > 0}"/>
                                </a>
                            </div>
                        </h:panelGroup>
                        <div class="post-content">
                            <h2><a href="#{request.contextPath}/item/#{item.id}/#{item.url}">#{item.name}</a></h2>
                            <h:panelGroup rendered="#{item.introduction != null}">
                                <p><h:outputText value="#{item.introduction}" escape="false"/></p>
                            </h:panelGroup>
                            <!-- <div class="date"><span>20 mar 2012</span></div> -->
                        </div>
                        <div class="clear"></div>
                    </article>
                </h:panelGroup>
            </ui:repeat>
            <div class="pagination">
                <ul>
                    <h:panelGroup rendered="#{categoryBean.pageNum > 1}">
                    <li>
                        <a href="#{request.contextPath}/category/#{categoryBean.categoryId}/page/#{categoryBean.pageNum-1}/#{categoryBean.currentCategory.url}">
                            <h:graphicImage value="#{resource['images:right-arrow.png']}" />
                        </a>
                    </li>
                    </h:panelGroup>
                    <ui:repeat value="#{categoryBean.pageNumList}" var="pageNum">
                        <li class="#{categoryBean.pageNum == pageNum ? 'current' : ''}">
                            <a href="#{request.contextPath}/category/#{categoryBean.categoryId}/page/#{pageNum}/#{categoryBean.currentCategory.url}">#{pageNum}</a>
                        </li>
                    </ui:repeat>
                    <h:panelGroup rendered="#{categoryBean.pageNum &lt; categoryBean.pageNumList.size()}">
                        <li>
                            <a href="#{request.contextPath}/category/#{categoryBean.categoryId}/page/#{categoryBean.pageNum+1}/#{categoryBean.currentCategory.url}">
                                <h:graphicImage value="#{resource['images:left-arrow.png']}" />
                            </a>
                        </li>
                    </h:panelGroup>
                </ul>
            </div>
        </div>
    </ui:define>
</ui:composition>